package com.niit.chapter2springbootreviewe.controller;

import com.niit.chapter2springbootreviewe.entity.User;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * @author hanli
 * @date 2025/3/5
 * @description TODO
 */
//@Controller  默认的请求是跳转
@RestController  // 默认全部的handler的返回值都是JSON
public class UserController {

    //@RequestMapping("/user")
    // /user?id=xxxx  @RequeParam
    // /user/{id}   /user/1001
    @GetMapping("/hello")
    public String getString(){
        return "abdd";
    }

    @GetMapping(value = "/user/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    public User getUser(@PathVariable("id") Integer id){
        User user = new User();
        user.setId(id);
        user.setName("hanliang");
        return user;
    }

}